package com.itheima.reggie.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie.common.BaseContext;
import com.itheima.reggie.common.R;
import com.itheima.reggie.dto.OrdersDto;
import com.itheima.reggie.entity.Orders;
import com.itheima.reggie.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.time.LocalDateTime;
import java.util.Date;

@RestController
@RequestMapping("/order")
public class OrdersController {
    @Autowired
    private OrdersService ordersService;

    //提交订单
    @PostMapping("/submit")
    public R<String> submitOrder(@RequestBody OrdersDto ordersDto) {
        ordersService.addOrder(ordersDto);
        return R.success("支付成功");
    }

    //查询订单详情
    @GetMapping("/userPage")
    public R<Page<OrdersDto>> orderPage(int page, int pageSize) {
        Long userId = BaseContext.getCurrendId();
        Page<OrdersDto> ordersDtoPage = ordersService.orderPage(userId, page, pageSize);
        return R.success(ordersDtoPage);
    }
    //查询订单详情
    @GetMapping("/page")
    public R<Page<OrdersDto>> ordersPage(int page, int pageSize, String number, @DateTimeFormat String beginTime, @DateTimeFormat String endTime) {
        Page<OrdersDto> ordersDtoPage = ordersService.orderPage(page, pageSize,number,beginTime,endTime);
        return R.success(ordersDtoPage);
    }
    //修改订单状态
    @PutMapping
    public R<String> updateStatus(@RequestBody Orders orders){
        ordersService.updateStatus(orders);
        return R.success("修改成功");
    }
}
